<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of RequireLogin
 *
 * @author Nahuel Chaves
 */
class RequireLogin extends CBehavior {

    public function attach($owner) {
        $owner->attachEventHandler('onBeginRequest', array($this, 'handleBeginRequest'));
    }

    public function handleBeginRequest($event) {
        $rutas = isset($_GET['r']) ? $_GET['r'] : null;
        if (Yii::app()->user->isGuest && !in_array($rutas, array('user/login'))) {
            Yii::app()->user->loginRequired();
        }
    }

}

?>
